﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web_Oto.Business;
using Web_Oto.Common;
using Web_Oto.Data;

namespace Web_Oto
{
    public partial class ServiceDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
                GetService();
        }

        //private void GetSeoInformations(string title, string key_descript)
        private void GetSeoInformations(ConsultService consultService)
        {
            //var seoBus = new SeoBus();
            //var seo = seoBus.GetSeoPage("service");
            //if (seo != null)
            //{
            //    Page.Title = title + " | " + seo.Title;
            //    Page.MetaDescription = key_descript + seo.Description;
            //    Page.MetaKeywords = key_descript + seo.Keyword;
            //}
            //else
            //{
            //    Page.Title = title;
            //    Page.MetaDescription = key_descript;
            //    Page.MetaKeywords = key_descript;
            //}
            Page.Title = consultService.SEO_Title;
            Page.MetaKeywords = consultService.SEO_Keyword;
            Page.MetaDescription = consultService.SEO_Description;            
        }

        private void GetService()
        {
            var serviceId = (Page.RouteData.Values.ContainsKey("serviceId"))
                ? Page.RouteData.GetRequiredString("serviceId") : null;
            if(serviceId != null)
            {
                var consultServiceBus = new ConsultServiceBus();
                var key_descript = "";
                var service = consultServiceBus.GetNewsById(int.Parse(serviceId));
                lblTitle.Text = service.Name;
                ltrDescription.Text = service.Description;
                lblserviceName.Text = service.Name;
                AnotherServices(int.Parse(serviceId), consultServiceBus, out key_descript);
                //GetSeoInformations(service.Name, key_descript);
                GetSeoInformations(service);
            }
            else
                Response.Redirect("/dich-vu-tu-van.html");
        }

        private void AnotherServices(int serviceId, ConsultServiceBus consultServiceBus, out string key_descript)
        {
            var lists = consultServiceBus.GetAnotherConsultService(serviceId);
            var sb = new StringBuilder();
            var str = "";
            foreach (var list in lists)
            {
                sb.AppendFormat("<li><a href='/dich-vu-tu-van/{0}/{1}.html'>{2}</a></li>", CommonHelper.NiceUrl(CommonHelper.RemoveSpecialChars(list.Name).Replace("  ", " ")).ToLower(), list.Id, list.Name);
                str += CommonHelper.NiceUrl(list.Name) + ", " + list.Name + ",";
            }
            key_descript = str;
            ltrAnotherServices.Text = sb.ToString();
        }
    }
}